package com.cust.zy.newtask.activity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.cust.zy.newtask.R;

import static android.content.Context.NOTIFICATION_SERVICE;

/**
 * Created by zhuangyuan on 4/22/2017.
 * 邮箱：zhuangyuan.k@qq.com
 */
public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {     // boot

            Intent openI = new Intent(context, WelcomeScreenActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            NotificationManager nm;
            nm = (NotificationManager)context.getSystemService(NOTIFICATION_SERVICE);
            PendingIntent pi = PendingIntent.getActivity(
                    context, 0, openI, 0);
            Notification notify = new Notification.Builder(context)
// 设置打开该通知，该通知自动消失
                    .setAutoCancel(true)
// 设置显示在状态栏的通知提示信息
                    .setTicker("有新消息")
// 设置通知的图标
                    .setSmallIcon(R.mipmap.ic_launcher)
// 设置通知内容的标题
                    .setContentTitle("一条新通知")
// 设置通知内容
                    .setContentText("")
// 设置使用系统默认的声音、默认LED灯
// .setDefaults(Notification.DEFAULT_SOUND
                    // |Notification.DEFAULT_LIGHTS)
                    // 设置通知的自定义声音
                    .setWhen(System.currentTimeMillis())
// 设改通知将要启动程序的Intent
                    .setContentIntent(pi)  // ①
                    .build();
        }
    }
}